package com.aoxin.controller.opm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.service.inter.opm.RoleMenuService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

/**
 * 角色Controller
 * 
 * @author Melody
 * @date 2018年3月21日 上午11:09:33
 */
@Controller
@ResponseBody
@RequestMapping("/web/roleMenu")
public class RoleMenuController {

	@Autowired
	private RoleMenuService roleMenuService;

	/**
	 * 批量添加角色菜单
	 * 
	 * @param roleId
	 *            角色ID
	 * @param menuIds
	 *            菜单ID集合
	 */
	@RequestMapping("insertRoleMenuList")
	@LogInfo(content = "角色菜单",operateType = OperateType.INSERT)
	public AjaxRes insertRoleMenuList(@RequestParam("roleId") Integer roleId, @RequestParam("menuIds") List<Integer> menuIds, AjaxRes ajaxRes) {
		try {
			this.roleMenuService.insertSlfRoleMenuList(roleId, menuIds);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 删除角色菜单
	 * 
	 * @param roleMenuIds
	 *            角色菜单集合
	 * @param ajaxRes
	 */
	@RequestMapping("deleteRoleMenus")
	@LogInfo(content = "角色菜单",operateType = OperateType.DELETE)
	public AjaxRes deleteRoleMenus(@RequestParam("roleMenuIds") List<Integer> roleMenuIds, AjaxRes ajaxRes) {
		try {
			this.roleMenuService.deleteSlfRoleMenuByIds(roleMenuIds);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
